package com.itheima.service;

import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.itheima.api.PmsBrandApi;
import com.itheima.pojo.db.PmsBrand;
import com.itheima.vo.PageResult;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chensen
 * @create 2022/10/12/19:45
 */
@Service
public class PmsBrandService {
    @DubboReference
    private PmsBrandApi pmsBrandApi;


    /**
     * 添加品牌
     *
     * @param pmsBrand
     */
    public void createBrand(PmsBrand pmsBrand) {
        boolean res = pmsBrandApi.createBrand(pmsBrand);
        if (!res) {
            throw new RuntimeException("添加失败");
        }
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    public void delete(List<Integer> ids) {
        pmsBrandApi.delete(ids);
    }

    /**
     * 单个删除
     *
     * @param id
     */
    public void deleteById(Integer id) {
        pmsBrandApi.deleteById(id);
    }

    /**
     * 根据条件分页查询品牌
     *
     * @param pageNum
     * @param pageSize
     * @param keyword
     * @return
     */
    public PageResult<PmsBrand> pageByCondition(Integer pageNum, Integer pageSize, String keyword) {
        PageResult<PmsBrand> page = pmsBrandApi.pageByCondition(pageNum, pageSize, keyword);
        if (ObjectUtils.isEmpty(page.getList())) {
            page.setList(new ArrayList<>());
        }
        return page;
    }

    /**
     * 查询所有品牌
     *
     * @return
     */
    public List<PmsBrand> listAll() {
        List<PmsBrand> pmsBrands = pmsBrandApi.listAll();
        return pmsBrands;
    }

    /**
     * 批量修改厂家制造商状态
     *
     * @param factoryStatus
     * @param ids
     * @return
     */
    public void upateFactoryStatus(Integer factoryStatus, List<Integer> ids) {
        if (ObjectUtils.isEmpty(factoryStatus) || ObjectUtils.isEmpty(ids)) {
            throw new RuntimeException("参数为空,请选择品牌与状态后再试");
        }
        pmsBrandApi.upateFactoryStatus(factoryStatus, ids);
    }

    /**
     * 批量修改显示状态
     *
     * @param showStatus
     * @param ids
     */
    public void upateShowStatus(Integer showStatus, List<Integer> ids) {
        if (ObjectUtils.isEmpty(showStatus) || ObjectUtils.isEmpty(ids)) {
            throw new RuntimeException("参数为空,请选择品牌与状态后再试");
        }
        pmsBrandApi.updateShowStatus(showStatus, ids);
    }

    /**
     * 修改单个品牌
     *
     * @param pmsBrand
     */
    public void updateById(PmsBrand pmsBrand) {
        pmsBrandApi.updateById(pmsBrand);
    }

    /**
     * 根据ID查询
     *
     * @param id
     */
    public PmsBrand findById(long id) {
        return pmsBrandApi.findById(id);
    }

}
